<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>时间戳技术指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            overflow-x: auto;
        }
        .drop-cap::first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 0.5rem;
            font-weight: 700;
            color: #667eea;
        }
        .timeline-dot {
            position: relative;
        }
        .timeline-dot::before {
            content: '';
            position: absolute;
            width: 12px;
            height: 12px;
            background: #667eea;
            border-radius: 50%;
            left: -6px;
            top: 50%;
            transform: translateY(-50%);
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto">
            <div class="text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6">
                    <i class="fas fa-clock mr-4"></i>时间戳技术指南
                </h1>
                <p class="text-xl md:text-2xl font-light max-w-3xl mx-auto">
                    探索时间戳的生成原理、实现方式与应用场景，掌握现代系统中时间记录的核心技术
                </p>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-6 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <div class="bg-white rounded-lg shadow-lg p-8 card-hover">
                <p class="text-lg leading-relaxed text-gray-700 drop-cap">
                    时间戳的生成涉及到从当前时间获取一个精确的表示形式，通常用于记录事件的发生时间、排序数据等。时间戳的生成通常是通过获取当前时间的数值表示来实现的，可以按秒、毫秒或纳秒进行计算。根据实际需求选择合适的时间精度和格式，以满足不同应用场景的要求。
                </p>
            </div>
        </section>

        <!-- Definition Section -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <i class="fas fa-book text-3xl text-purple-600 mr-4"></i>
                <h2 class="text-3xl font-bold text-gray-800">时间戳的定义</h2>
            </div>
            <div class="bg-white rounded-lg shadow-lg p-8 card-hover">
                <p class="text-lg leading-relaxed text-gray-700">
                    时间戳是一个用来表示特定时刻的数字或字符串，通常以毫秒或秒为单位。从计算机系统的角度来看，时间戳通常是一个长整型数字，表示自某个基准时间（如1970年1月1日00:00:00 UTC）以来的时间量。
                </p>
            </div>
        </section>

        <!-- Visualization -->
        <section class="mb-16">
            <div class="bg-white rounded-lg shadow-lg p-8">
                <h3 class="text-2xl font-bold text-gray-800 mb-6 text-center">时间戳体系结构</h3>
                <div class="mermaid">
                    graph TD
                        A[时间戳系统] --> B[精度级别]
                        A --> C[格式类型]
                        A --> D[应用场景]
                        
                        B --> B1[秒级]
                        B --> B2[毫秒级]
                        B --> B3[纳秒级]
                        
                        C --> C1[数值格式]
                        C --> C2[ISO 8601]
                        C --> C3[自定义格式]
                        
                        D --> D1[数据记录]
                        D --> D2[数据排序]
                        D --> D3[唯一标识]
                        
                        style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                        style B fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                        style C fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                        style D fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                </div>
            </div>
        </section>

        <!-- Generation Methods -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <i class="fas fa-cogs text-3xl text-purple-600 mr-4"></i>
                <h2 class="text-3xl font-bold text-gray-800">常见时间戳生成方式</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <!-- 基于当前时间 -->
                <div class="bg-white rounded-lg shadow-lg p-8 card-hover">
                    <h3 class="text-xl font-bold text-gray-800 mb-4">
                        <i class="fas fa-calendar-alt text-purple-600 mr-2"></i>基于当前时间
                    </h3>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <span><strong>秒级时间戳：</strong>表示自基准时间以来的秒数</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <span><strong>毫秒级时间戳：</strong>表示自基准时间以来的毫秒数</span>
                        </li>
                    </ul>
                </div>

                <!-- 高精度计时器 -->
                <div class="bg-white rounded-lg shadow-lg p-8 card-hover">
                    <h3 class="text-xl font-bold text-gray-800 mb-4">
                        <i class="fas fa-stopwatch text-purple-600 mr-2"></i>使用高精度计时器
                    </h3>
                    <p class="text-gray-700">
                        对于需要更高精度的时间戳，可以使用系统提供的高精度计时器（如纳秒级时间戳），适用于性能测试和高频数据记录场景。
                    </p>
                </div>
            </div>
        </section>

        <!-- Code Examples -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <i class="fas fa-code text-3xl text-purple-600 mr-4"></i>
                <h2 class="text-3xl font-bold text-gray-800">代码示例</h2>
            </div>

            <div class="space-y-8">
                <!-- Java Examples -->
                <div class="bg-white rounded-lg shadow-lg overflow-hidden">
                    <div class="bg-purple-600 text-white px-6 py-3">
                        <h4 class="font-bold">Java 实现</h4>
                    </div>
                    <div class="p-6">
                        <h5 class="font-semibold text-gray-800 mb-3">秒级时间戳</h5>
                        <pre class="code-block p-4 mb-6"><code>long timestampInSeconds = System.currentTimeMillis() / 1000;
System.out.println("秒级时间戳: " + timestampInSeconds);</code></pre>
                        
                        <h5 class="font-semibold text-gray-800 mb-3">毫秒级时间戳</h5>
                        <pre class="code-block p-4 mb-6"><code>long timestampInMillis = System.currentTimeMillis();
System.out.println("毫秒级时间戳: " + timestampInMillis);</code></pre>
                        
                        <h5 class="font-semibold text-gray-800 mb-3">纳秒级时间戳</h5>
                        <pre class="code-block p-4 mb-6"><code>long timestampInNanos = System.nanoTime();
System.out.println("纳秒级时间戳: " + timestampInNanos);</code></pre>
                        
                        <h5 class="font-semibold text-gray-800 mb-3">ISO 8601 格式</h5>
                        <pre class="code-block p-4"><code>import java.time.Instant;
String isoTimestamp = Instant.now().toString();
System.out.println("ISO 8601 时间戳: " + isoTimestamp);</code></pre>
                    </div>
                </div>

                <!-- Python Example -->
                <div class="bg-white rounded-lg shadow-lg overflow-hidden">
                    <div class="bg-purple-600 text-white px-6 py-3">
                        <h4 class="font-bold">Python 实现</h4>
                    </div>
                    <div class="p-6">
                        <h5 class="font-semibold text-gray-800 mb-3">ISO 8601 格式</h5>
                        <pre class="code-block p-4"><code>from datetime import datetime
iso_timestamp = datetime.utcnow().isoformat()
print("ISO 8601 时间戳:", iso_timestamp)</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Applications -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <i class="fas fa-rocket text-3xl text-purple-600 mr-4"></i>
                <h2 class="text-3xl font-bold text-gray-800">时间戳的应用</h2>
            </div>
            
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white rounded-lg shadow-lg p-6 card-hover text-center">
                    <i class="fas fa-database text-4xl text-purple-600 mb-4"></i>
                    <h4 class="text-xl font-bold text-gray-800 mb-2">数据记录</h4>
                    <p class="text-gray-600">用于记录事件发生的时间</p>
                </div>
                
                <div class="bg-white rounded-lg shadow-lg p-6 card-hover text-center">
                    <i class="fas fa-sort text-4xl text-purple-600 mb-4"></i>
                    <h4 class="text-xl font-bold text-gray-800 mb-2">数据排序</h4>
                    <p class="text-gray-600">在数据库或日志中用于排序数据</p>
                </div>
                
                <div class="bg-white rounded-lg shadow-lg p-6 card-hover text-center">
                    <i class="fas fa-fingerprint text-4xl text-purple-600 mb-4"></i>
                    <h4 class="text-xl font-bold text-gray-800 mb-2">数据唯一性</h4>
                    <p class="text-gray-600">通过时间戳生成唯一的标识符</p>
                </div>
            </div>
        </section>

        <!-- Precision and Range -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <i class="fas fa-chart-line text-3xl text-purple-600 mr-4"></i>
                <h2 class="text-3xl font-bold text-gray-800">时间戳的精度和范围</h2>
            </div>
            
            <div class="bg-white rounded-lg shadow-lg overflow-hidden">
                <table class="w-full">
                    <thead class="bg-purple-600 text-white">
                        <tr>
                            <th class="px-6 py-4 text-left">精度级别</th>
                            <th class="px-6 py-4 text-left">适用场景</th>
                            <th class="px-6 py-4 text-left">特点</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-200">
                        <tr class="hover:bg-gray-50 transition-colors">
                            <td class="px-6 py-4 font-semibold">秒级</td>
                            <td class="px-6 py-4">大多数应用场景</td>
                            <td class="px-6 py-4">精度较低，但满足常规需求</td>
                        </tr>
                        <tr class="hover:bg-gray-50 transition-colors">
                            <td class="px-6 py-4 font-semibold">毫